#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

#define FILE_GETTIME_CONTROL 1

enum eBackState{
    eSUCCESS = 0,
    eERROR = -1,
};

int main(int argc, char **argv)
{
    struct timespec tmsp_arr[2];
    int fd;
    int ret = 0;

    if(eERROR == access(argv[1], F_OK)){
        printf("%s: file doesn't exist!\n", argv[1]);
        exit(-1);
    }

    if(eERROR == open(argv[1], O_RDONLY)){
        perror("open error");
        exit(-1);
    }

#if FILE_GETTIME_CONTROL
    ret = futimens(fd, NULL);
#else
    tmsp_arr[0].tv_nsec = UTIME_OMIT;
    tmsp_arr[1].tv_nsec = UTIME_NOW;
    ret = futimens(fd, tmsp_arr);
#endif

    if(eERROR == ret)
        perror("futimens error");

    close(fd);
    exit(ret);
}
